package cate.game.role.farm.island;

import cate.common.table.d.GDFight;
import cate.common.table.d.GDHoardTask;
import cate.common.table.farm.island.row.IslandGuardGroupRow;
import cate.game.play.proce.play.PlayPO;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;
import cate.game.role.farm.island.cell.FightSideCell;
import easy.java.practice.errorcode.EcResult;

public class IslandFTC extends AbstractFarmFTC<Island> {
    public IslandGuardGroupRow row;

    public FightSideCell cell;

    public IslandFTC(Role role, IslandGuardGroupRow row, FightSideCell cell) {
        setup(role);
        this.row = row;
        this.cell = cell;
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        boolean win = play.winner == GDFight.Team.A;
        if (win) {
            cell.win(play);
        }
        cell.record(play);
        Island island = po(role);
        island.record.updateHeroState(play.teamEnd.a.getAllHero());
        island.record.noticeHeroStateUpdate();
        EcResult<Void> r = island.beginChallenge(cell, row, play);
        role.getGame().notice.message(role, r,true);
        if (!island.ifHoard) {
            boolean check = role.getRes().hoard.addition.addTask(GDHoardTask.ISLAND);
            island.ifHoard = check;
        }

    }

    @Override
    protected Island po(Role role) {
        return role.getFarm().island;
    }
}
